<?php

use App\Http\Controllers\Api\AuthorizationsController;
use App\Http\Controllers\Api\CaptchasController;
use App\Http\Controllers\Api\CategoriesController;
use App\Http\Controllers\Api\ImagesController;
use App\Http\Controllers\Api\LinksController;
use App\Http\Controllers\Api\NotificationsController;
use App\Http\Controllers\Api\PermissionsController;
use App\Http\Controllers\Api\RepliesController;
use App\Http\Controllers\Api\TopicsController;
use App\Http\Controllers\Api\UsersController;
use App\Http\Controllers\Api\VerificationCodesController;
use App\Http\Resources\PermissionResource;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use Overtrue\EasySms\EasySms;

Route::prefix('v1')->middleware('change-locale')->name('api.v1.')->group(function (){
    //低频率访问限制
    Route::middleware('throttle:30,1')->group(function (){
        //发送手机短信
        Route::post('verificationCodes',[VerificationCodesController::class,'store'])->name('verificationCodes.store');
        //用户注册
        Route::post('users',[UsersController::class,'store'])->name('users.store');
        //显示图片验证码
        Route::post('captchas',[CaptchasController::class,'store'])->name('captchas.store');
        //第三方登录
        Route::post('socials/{social_type}/authorizations',[AuthorizationsController::class,'socialStore'])
        ->where('social_type','wechat')
        ->name('socials.authorizations.store');
        //普通登录
        Route::post('authorizations',[AuthorizationsController::class,'store'])->name('authorizations.store');
        //小程序的登录或绑定邮箱手机
        Route::post('weapp/authorizations',[AuthorizationsController::class,'weappStore'])->name('weapp.authorizations.store');
        // 小程序注册
        Route::post('weapp/users', [UsersController::class, 'weappStore'])->name('weapp.users.store');
        // 刷新token
        Route::put('authorizations/current', [AuthorizationsController::class, 'update'])->name('authorizations.update');
        //小程序端退出登录
        Route::delete('authorizations/current', [AuthorizationsController::class, 'destroy'])->name('authorizations.destroy');
    });

    //高频率访问限制
    Route::middleware('throttle:60,1')->group(function (){
        /****游客身份可访问的路由***/
        //获取某个用户个人信息
        Route::get('users/{user}',[UsersController::class,'show'])->name('users.show');
        //帖子分类
        Route::apiResource('categories',CategoriesController::class)->only(['index']);
        //帖子的列表和详情
        Route::apiResource('topics',TopicsController::class)->only(['index','show']);
        //某人发的帖子
        Route::get('users/{user}/topics',[TopicsController::class,'userIndex'])->name('users.topics.index');
        //评论相关
        Route::apiResource('topics.replies',RepliesController::class)->only(['index']);
        // 某个用户的评论列表
        Route::get('users/{user}/replies', [RepliesController::class, 'userIndex'])->name('users.replies.index');
        Route::apiResource('links',LinksController::class)->only(['index']);
        Route::get('actived/users',[UsersController::class,'activedUsers'])->name('actived.users.index');
        /****登录后才可访问的路由***/
        Route::middleware('auth:api')->group(function (){
            Route::get('user',[UsersController::class,'me'])->name('user.me');
            //上传图片
            Route::post('images',[ImagesController::class,'store'])->name('images.store');
            //编辑用户信息
            Route::patch('user',[UsersController::class,'update'])->name('user.update');
            //小程序编辑用户信息
            Route::put('user',[UsersController::class,'update'])->name('user.update');
            Route::apiResource('topics',TopicsController::class)->only(['store','update','destroy']);
            //评论相关
            Route::apiResource('topics.replies',RepliesController::class)->only(['store','destroy']);
            //未读信息通知总数
            Route::get('notifications/stats',[NotificationsController::class,'stats'])->name('notifications.stats');
            //消息通知队列
            Route::apiResource('notifications',NotificationsController::class)->only(['index']);
            //消息通知设置为已读状态
            Route::patch('user/read/notifications',[NotificationsController::class,'read'])->name('user.notifications.read');
            Route::put('user/read/notifications', [NotificationsController::class, 'read'])->name('user.notifications.read');
            //用户权限列表
            Route::get('user/permissions',[PermissionsController::class,'index'])->name('user.permissions.index');
        });
    });

});



